// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
var url;

function getrestMsg() {
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height()
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/user/getLoadedOthersLikeOfMe?pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          //
          console.log("加载数据请求已发送");
          let allnews = document.querySelector("#news");

          for (let i = 0; i < result.length; i++) {
            //   判断是赞评论还是赞文章
            let likes = result[i];
            let state = result[i].state;
            let myInfo = result[i].myInfo;
            let othersInfo = result[i].othersInfo;

            if (!result[i].blogUrl) {
              url = result[i].myInfo.avatarUrl;
            } else {
              url = result[i].blogUrl;
            }
            if (state == 0) {
              allnews.innerHTML += `
                <div class="news add" >
                <div class="news-top">
                  <a  href="/user/toOnesInfo?id=${likes.userId}" class="head-link">
                    <div class="head">
                      <img src="${othersInfo.avatarUrl}"  alt="" />
                    </div>
                  </a>
                  <div class="top-details">
                    <a href="" class="name" >
                      <p >${othersInfo.username}</p>
                    </a>
                    <p class="time" >${likes.likeTime} ${likes.othersInfo.address}</p>
                  </div>
                </div>
                <div class="message-content" ><p 
                >赞了这条微博</p></div>
                <div class="message-container" href="/weibo/blog/skipInEnvelope?id=${likes.blogId}">
                  <div class="message-content-img">
                    <img src="${url}"  alt="" />
                    
                  </div>
                  <div class="message-content-text">
                    <p><span>@</span><span >${likes.myInfo.username}</span></p>
                    <p   class="message-content-blog">${likes.blogText}</p>
      
                  </div>
                </div>
              </div>
                `;
            } else if (state == 1) {
              allnews.innerHTML += `
                <div class="news add" >
                <div class="news-top">
                  <a  href="/user/toOnesInfo?id=${likes.userId}" class="head-link">
                    <div class="head">
                      <img src="${othersInfo.avatarUrl}"  alt="" />
                    </div>
                  </a>
                  <div class="top-details">
                    <a href="" class="name" >
                      <p >${othersInfo.username}</p>
                    </a>
                    <p class="time" >${likes.likeTime} ${likes.othersInfo.address}</p>
                  </div>
                </div>
                <div class="message-content" ><p >赞了这条评论</p></div>
               
                <div class="message-container-box"  href="/weibo/blog/skipInEnvelope?id=${likes.blogId}">
                  <div class="message-container-item1" ><a class="color">@${likes.myInfo.username}</a><span >:${likes.commentText}</span></div>
                  <div class="message-container">
                    <div class="message-content-img">
                      <img src="${url}" alt="" />
                     
                    </div>
                    <div class="message-content-text">
                      <p>
                        <span>@</span><span th:text="">${likes.myInfo.username}</span>
                      </p>
                      <p  class="message-content-blog">${likes.blogText}</p>
                    </div>
                  </div>
                </div>
              </div>
                `;
            }
          }
          if (result.length >= 0 && result.length < 10) {
            document.querySelector(".none").classList.remove("hidden");
          }
          switchoverfn();
        },
      });
    }
  });
}
getrestMsg();
